/*     */ package com.feeyin.radar.sys.dao.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.dao.DepartmentDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.model.Department;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import org.springframework.orm.ibatis.SqlMapClientTemplate;
/*     */ import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
/*     */ 
/*     */ public class DepartmentDAOImpl extends SqlMapClientDaoSupport
/*     */   implements DepartmentDAO
/*     */ {
/*     */   private UserDAO userDAO;
/*     */ 
/*     */   public String getCurrentDeptUserIdAndSubDeptsUserIdsByUserId(Integer userId)
/*     */   {
/*  24 */     List deptids = getCurrentDeptAndSubDeptsByUserId(userId);
/*  25 */     String salePersonIds = "";
/*  26 */     for (int i = 0; i < deptids.size(); i++) {
/*  27 */       Integer deptId = ((Department)deptids.get(i)).getId();
/*  28 */       List users = this.userDAO.getUserActivityByDeptId(deptId);
/*  29 */       if (users != null) {
/*  30 */         for (int j = 0; j < users.size(); j++) {
/*  31 */           Users u = (Users)users.get(j);
/*  32 */           if (j == users.size() - 1)
/*  33 */             salePersonIds = salePersonIds + u.getId();
/*     */           else {
/*  35 */             salePersonIds = salePersonIds + u.getId() + ",";
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*  40 */     return salePersonIds;
/*     */   }
/*     */ 
/*     */   public UserDAO getUserDAO()
/*     */   {
/*  46 */     return this.userDAO;
/*     */   }
/*     */ 
/*     */   public void setUserDAO(UserDAO userDAO) {
/*  50 */     this.userDAO = userDAO;
/*     */   }
/*     */ 
/*     */   public List getDepartments() {
/*  54 */     return getSqlMapClientTemplate().queryForList("getDepartments");
/*     */   }
/*     */ 
/*     */   public List getDepartmentsByActivity() {
/*  58 */     return getSqlMapClientTemplate().queryForList("getDepartmentsByActivity");
/*     */   }
/*     */ 
/*     */   public List getDepartmentByDeptSeq(String deptSeq) {
/*  62 */     return getSqlMapClientTemplate().queryForList("getDepartmentByDeptSeq", deptSeq);
/*     */   }
/*     */ 
/*     */   public List getDepartmentByParentId(Integer parentId) {
/*  66 */     return getSqlMapClientTemplate().queryForList("getDepartmentByParentId", parentId);
/*     */   }
/*     */ 
/*     */   public Department getDepartment(Integer id) {
/*  70 */     return (Department)getSqlMapClientTemplate().queryForObject("getDepartment", id);
/*     */   }
/*     */ 
/*     */   public Department getDepartmentByDeptCode(String deptCode) {
/*  74 */     return (Department)getSqlMapClientTemplate().queryForObject("getDepartmentByDeptCode", deptCode);
/*     */   }
/*     */ 
/*     */   public Department getDepartmentByDeptName(String deptName) {
/*  78 */     return (Department)getSqlMapClientTemplate().queryForObject("getDepartmentByDeptName", deptName);
/*     */   }
/*     */ 
/*     */   public Integer getDepartmentMaxId() {
/*  82 */     return (Integer)getSqlMapClientTemplate().queryForObject("getDepartmentMaxId");
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptIdAndSubDeptIdsByDeptId(Integer deptId) {
/*  86 */     if (deptId == null) return null;
/*  87 */     Department department = new Department();
/*  88 */     department = getDepartment(deptId);
/*     */ 
/*  90 */     if (department == null) return null;
/*  91 */     List subDepts = new ArrayList();
/*  92 */     subDepts = getDepartmentByDeptSeq(department.getDeptSeq());
/*     */ 
/*  94 */     if ((subDepts == null) || (subDepts.size() <= 0)) return null;
/*     */ 
/*  96 */     String deptIds = "";
/*  97 */     for (int i = 0; i < subDepts.size(); i++) {
/*  98 */       Department dept = new Department();
/*  99 */       dept = (Department)subDepts.get(i);
/* 100 */       if (i == subDepts.size() - 1)
/* 101 */         deptIds = deptIds + dept.getId();
/*     */       else {
/* 103 */         deptIds = deptIds + dept.getId() + ",";
/*     */       }
/*     */     }
/* 106 */     return deptIds;
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptIdAndSubDeptIdsByUserId(Integer userId)
/*     */   {
/* 111 */     if (userId == null) return null;
/* 112 */     Users user = new Users();
/* 113 */     user = this.userDAO.getUser(userId);
/* 114 */     if ((user == null) || (user.getDeptId() == null)) return null;
/* 115 */     Department department = new Department();
/* 116 */     department = getDepartment(user.getDeptId());
/* 117 */     if (department == null) return null;
/* 118 */     return getCurrentDeptIdAndSubDeptIdsByDeptId(department.getId());
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptNameAndSubDeptNamesByUserId(Integer userId) {
/* 122 */     if (userId == null) return null;
/* 123 */     Users user = new Users();
/* 124 */     user = this.userDAO.getUser(userId);
/* 125 */     if ((user == null) || (user.getDeptId() == null)) return null;
/* 126 */     Department department = new Department();
/* 127 */     department = getDepartment(user.getDeptId());
/*     */ 
/* 129 */     if (department == null) return null;
/* 130 */     List subDepts = new ArrayList();
/* 131 */     subDepts = getDepartmentByDeptSeq(department.getDeptSeq());
/*     */ 
/* 133 */     if ((subDepts == null) || (subDepts.size() <= 0)) return null;
/* 134 */     String deptNames = "";
/* 135 */     for (int i = 0; i < subDepts.size(); i++) {
/* 136 */       Department dept = new Department();
/* 137 */       dept = (Department)subDepts.get(i);
/* 138 */       if (i == subDepts.size() - 1)
/* 139 */         deptNames = deptNames + dept.getDeptName();
/*     */       else {
/* 141 */         deptNames = deptNames + dept.getDeptName() + ",";
/*     */       }
/*     */     }
/* 144 */     return deptNames;
/*     */   }
/*     */ 
/*     */   public List getCurrentDeptAndSubDeptsByUserId(Integer userId) {
/* 148 */     if (userId == null) return null;
/* 149 */     Users user = new Users();
/* 150 */     user = this.userDAO.getUser(userId);
/* 151 */     if ((user == null) || (user.getDeptId() == null)) return null;
/* 152 */     Department department = new Department();
/* 153 */     department = getDepartment(user.getDeptId());
/*     */ 
/* 155 */     if (department == null) return null;
/* 156 */     List subDepts = new ArrayList();
/* 157 */     subDepts = getDepartmentByDeptSeq(department.getDeptSeq());
/* 158 */     return subDepts;
/*     */   }
/*     */ 
/*     */   public boolean insertDepartment(Department department) {
/* 162 */     if (department == null) return false;
/* 163 */     if (StringUtils.isEmpty(department.getDeptCode())) return false;
/*     */ 
/* 165 */     getSqlMapClientTemplate().insert("insertDepartment", department);
/* 166 */     return getDepartmentByDeptCode(department.getDeptCode()) != null;
/*     */   }
/*     */ 
/*     */   public boolean updateDepartment(Department department)
/*     */   {
/* 172 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().update("updateDepartment", department));
/* 173 */     return result != null;
/*     */   }
/*     */ 
/*     */   public boolean deleteDepartment(Integer id)
/*     */   {
/* 178 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().delete("deleteDepartment", id));
/* 179 */     return result != null;
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.dao.impl.DepartmentDAOImpl
 * JD-Core Version:    0.6.0
 */